<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.currency}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
        <h:form >
           <script type="text/javascript">  
                
                function handleSaveCurrency(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgCurrency.hide();  
                    }  
                }
                
                function handleDeleteCurrency(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgDelCurrency.hide();  
                    }  
                }
  
            </script>  

            <p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton value="#{bundle.btnNew}"
                                     icon="ui-icon-document" rendered="#{menuBean.cekButtonAccess(561,'INS;')}"
                                     action="#{currencyBean.newData()}"  
                                     oncomplete="dlgCurrency.show()"
                                     update=":#{utilityBean.findClientId('displayCurrency')}" process="@this">
                            <pe:resetEditableValues for="displayCurrency" />  
                        </p:commandButton>   

                    <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgCurrency.show()" rendered="#{menuBean.cekButtonAccess(561,'OPN;')}"
                                     icon="ui-icon-disk" action="#{currencyBean.openData()}"
                                     update=":#{utilityBean.findClientId('displayCurrency')}" > 
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnDelete}" icon="ui-icon-trash" rendered="#{menuBean.cekButtonAccess(561,'DEL;')}"
                                     onclick="dlgDelCurrency.show()" /> 

                </p:toolbarGroup>
            </p:toolbar>
            <br />
            <p:dataTable var="currency" value="#{currencyBean.currencys}" id="dtCurrencys" resizableColumns="true"
                         rowIndexVar="noUrut" selection="#{currencyBean.selectedData}" selectionMode="single" 
                         rowKey="#{currency.currencyId}" sortBy="#{currency.currencyName}">
                 <p:column style="width: 12px;">
                    <f:facet name="header">No.</f:facet>
                    <h:outputText value="#{noUrut+1}" />
                 </p:column>
                <p:column style="width:auto" sortBy="#{currency.currencyName}">
                    <f:facet name="header">#{bundle.globalName}</f:facet>
                    <h:outputText value="#{currency.currencyName}" />
                </p:column>
                <p:column style="width:30px;">
                    <f:facet name="header">#{bundle.symbol}</f:facet>
                    <h:outputText value="#{currency.symbol}" />
                </p:column>
                <p:column style="width:100px;">
                    <f:facet name="header">#{bundle.exchangeRate}</f:facet>
                    <h:outputText value="#{currency.exchangeRate}" styleClass="numPos">
                        <f:convertNumber groupingUsed="#{true}"/>
                    </h:outputText>
                </p:column>
            </p:dataTable>
          
            <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                             header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgDelCurrency">
                <h:panelGrid cellspacing="0" cellpadding="0" styleClass="pComBtnD">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnYes}" update="dtCurrencys" process="@this"
                                         oncomplete="handleDeleteCurrency(xhr, status, args)"  
                                         actionListener="#{currencyBean.delete()}" />  
                        <p:commandButton value="#{bundle.btnCancel}" onclick="dlgDelCurrency.hide()" type="button" />
                    </f:facet>
                </h:panelGrid>   
            </p:confirmDialog>
        </h:form>
            <p:dialog header="#{bundle.currency}" widgetVar="dlgCurrency" closable="true" dynamic="true" modal="true" appendToBody="true">
                <p:ajax immediate="true" event="close" listener="#{currencyBean.handleClose}"/>
                <h:form>
                <p:focus context="displayCurrency" />
                <h:panelGrid id="displayCurrency" columns="3" styleClass="addELIT">
                    <h:outputLabel value= "#{bundle.globalName}" /><h:outputLabel value= ":" />
                    <h:panelGrid columns="2" cellpadding="0" cellspacing="0" rendered="#{currencyBean.insertedData!=null}">
                        <p:inputText value="#{currencyBean.insertedData.currencyName}" 
                                     required="true" label="#{bundle.globalName}" size="25" 
                                     requiredMessage="#{bundle.globalName} #{bundle.requiredInput}"
                                     id="currencyName1" >
                                <p:ajax event="keyup" update="msgcurrencyName1" process="@this"/>
                        </p:inputText>
                        <p:message id="msgcurrencyName1" for="currencyName1" display="icon" />
                   </h:panelGrid>
                    
                    <h:outputLabel value= "#{bundle.symbol}" /><h:outputLabel value= ":" />
                    <h:panelGrid columns="2" cellpadding="0" cellspacing="0" rendered="#{currencyBean.insertedData!=null}">
                        <p:inputText value="#{currencyBean.insertedData.symbol}" 
                            required="true" label="#{bundle.symbol}" size="25" 
                            requiredMessage="#{bundle.symbol} #{bundle.requiredInput}" id="symbol1" >
                            <p:ajax update="msgsymbol1" process="@this"/>
                        </p:inputText>
                        <p:message id="msgsymbol1" for="symbol1" display="icon" />
                    </h:panelGrid>
                    
                    <h:outputLabel style="padding: 0 15px 0 0" value= "#{bundle.exchangeRate}" /><h:outputLabel value= ":" />
                    <h:panelGrid columns="2" cellpadding="0" cellspacing="0" rendered="#{currencyBean.insertedData!=null}">
                        <pe:inputNumber decimalSeparator="." thousandSeparator="," maxValue="99999999999999.99" minValue="0" 
                            value="#{currencyBean.insertedData.exchangeRate}"  
                                        required="true" styleClass="money" 
                                        requiredMessage="#{bundle.exchangeRate} #{bundle.requiredInput}" id="currencyExchangeRate1" >
                            <p:ajax update="msgcurrencyExchangeRate1" process="@this"/>
                        </pe:inputNumber>
                        <p:message id="msgcurrencyExchangeRate1" for="currencyExchangeRate1" display="icon" />
                    </h:panelGrid>
                </h:panelGrid>
              
                <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{currencyBean.save()}" rendered="#{menuBean.cekButtonAccess(561,'UPD;')}"
                                         update=":#{utilityBean.findClientId('dtCurrencys')}" id="submitCurrency"
                                         oncomplete="handleSaveCurrency(xhr, status, args)"/>
                        <p:commandButton value="#{bundle.btnClose}" oncomplete="dlgCurrency.hide()" icon="ui-icon-document" 
                                         process="@this">
                            <pe:resetEditableValues for="displayCurrency" />  
                        </p:commandButton>
                    </f:facet>
                </h:panelGrid>
                </h:form>
                <!--<p:defaultCommand target="submitCurrency" /> -->
            </p:dialog> 
        
        </ui:composition>    
    </h:body>
</html>